package emails

import (
	"autoDeploy/service/email"
	"github.com/gin-gonic/gin"
	"github.com/golang-jwt/jwt"
)

type Email struct{}

func (e Email) GetEmails(c *gin.Context) {
	claims, _ := c.Get("claims")
	if claims != nil {
		claimsMap := claims.(jwt.MapClaims)
		//从token中获取用户id
		UserIdFloat := claimsMap["user_id"].(float64)
		UserId := uint64(int64(UserIdFloat))
		//调用service层的方法获取全部邮件
		emails, err := email.GetAllEmails(UserId)
		if err != nil {
			c.JSON(200, gin.H{"code": 0, "message": err.Error()})
			return
		}
		c.JSON(200, gin.H{"code": 1, "message": "获取信息成功", "emails": emails})
		return
	}
}
